package com.example.demo3.controller;

;

import com.example.demo3.entity.VO.Category;
import com.example.demo3.service.ICategoryService;
import com.example.demo3.utils.PageResult;
import com.example.demo3.utils.PassToken;
import com.example.demo3.utils.ServiceResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * categorysController
 * 
 * @author ruoyi
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/system/category")
public class CategoryController
{
    @Autowired
    private ICategoryService categoryService;
    @PassToken

    /**
     * 查询categorys列表
     */
    @GetMapping("/list")
    public ServiceResponse list(Category category, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize)
    {
        PageResult pageResult = categoryService.selectCategoryList(category,pageNum,pageSize);
        return ServiceResponse.createBySuccess(200,pageResult,"获取成功");
    }


    @GetMapping("/list1")
    @PassToken
    public ServiceResponse list1(Category category, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize)
    {
        PageResult pageResult = categoryService.selectCategoryGoodsList(category,pageNum,pageSize);
        return ServiceResponse.createBySuccess(200,pageResult,"获取成功");
    }

    /**
     * 获取categorys详细信息
     */
    @GetMapping(value = "/{cid}")
    public ServiceResponse getInfo(@PathVariable("cid") Long cid)
    {
        return ServiceResponse.createBySuccess(200,categoryService.selectCategoryByCid(cid),"获取成功");
    }

    /**
     * 新增categorys
     */
    @PostMapping
    public ServiceResponse add(@RequestBody Category category)
    {
        int i = categoryService.insertCategory(category);
        if(i>0){
            return ServiceResponse.createBySuccess(200,"","添加成功");
        }else{
            return  ServiceResponse.createByFail(500,"添加失败");

        }
    }

    /**
     * 修改categorys
     */
    @PutMapping
    public ServiceResponse edit(@RequestBody Category category)
    {
        int i = categoryService.updateCategory(category);
        if(i>0){
            return ServiceResponse.createBySuccess(200,"","添加成功");
        }else{
            return  ServiceResponse.createByFail(500,"添加失败");

        }
    }

    /**
     * 删除categorys
     */
	@DeleteMapping("/{cids}")
    public ServiceResponse remove(@PathVariable Long[] cids)
    {
        int i = categoryService.deleteCategoryByCids(cids);
        if(i>0){
            return ServiceResponse.createBySuccess(200,"","删除成功");
        }else{
            return  ServiceResponse.createByFail(500,"删除失败");

        }
    }
}
